package cn.hxth.cloud.provider.builder;

import cn.hxth.cloud.api.common.constant.ProcedureStatus;
import cn.hxth.cloud.api.domain.OrderInfo;
import cn.hxth.cloud.api.domain.OrderInfoItem;
import cn.hxth.cloud.api.domain.Product;
import cn.hxth.cloud.api.domain.ProductionOrder;
import cn.hxth.cloud.api.common.constant.ProcedureType;
import cn.hxth.cloud.api.common.util.DateProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
public class ProductionOrderBuilder {
    @Autowired
    private DateProvider dateProvider ;
    private ProductionOrder productionOrder = new ProductionOrder() ;
    public ProductionOrderBuilder setOrderInfoProperties(OrderInfo orderInfo){
        productionOrder.setDeliveryDate(orderInfo.getDeliveryDate());
        productionOrder.setOid(orderInfo.getId());
        productionOrder.setOrderInfo(orderInfo);
        return  this ;
    }

    public ProductionOrderBuilder setOrderItemsProperties(OrderInfoItem item) {
        productionOrder.setNeedCount(item.getCount());
        productionOrder.setPlanCount(item.getCount()+1000);
        return  this ;
    }
    public  ProductionOrderBuilder setProductProperties(Product product){
        productionOrder.setSid(product.getSid());
        productionOrder.setSteels(product.getSteels());
        productionOrder.setProcedureType(product.getThickness()>1000? ProcedureType.COLD:ProcedureType.HEAT);
        productionOrder.setProduct(product);
        productionOrder.setPid(product.getId());
        return  this ;
    }
    public  ProductionOrderBuilder initProductionOrder() throws Exception {
        productionOrder.setProcedureStatus(ProcedureStatus.STOCKING);
        productionOrder.setMakeDate(dateProvider.getCurrentTime());
        productionOrder.setSteelsCount(1000l);
        return  this ;
    }

    public ProductionOrder create(){
        return this.productionOrder;
    }
}
